<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"      
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui"
    template="/templates/layout.xhtml">
	
	<ui:define name="content">
		
		<ui:include src="../protected/dialogs/new_user.xhtml"/>	
		
		<div align="left">
		<h:form id="user_form">
			<p:growl id="growl" sticky="true" showDetail="true" showSummary="true" autoUpdate="true"  />
			<h:panelGrid>
				<p:commandButton value="Add user" actionListener="#{usersBean.addNewUser}"
					update=":new_user_form" icon="ui-icon-circle-plus" />
			</h:panelGrid>
				
			<p:spacer height="10" />
			
			<p:dataTable var="user" value="#{usersBean.userDataModel}" paginator="true" rows="10" widgetVar="userTable"
            	paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
            	rowsPerPageTemplate="5,10,15" id="usersTable" lazy="true" paginatorPosition="both" scrollable="false" 
            	paginatorAlwaysVisible="true">
    			
    			<p:column headerText="Name" sortBy="#{user.name}" filterPosition="bottom" filterBy="#{user.name}">
    				<h:outputText value="#{user.name}" />
    			</p:column>
    			
    			<p:column headerText="Login" sortBy="#{user.login}" filterPosition="bottom" filterBy="#{user.login}">
    				<h:outputText value="#{user.login}" />
    			</p:column>
    			
    			<p:column headerText="E-mail">
    				<h:outputText value="#{user.email}"/>
    			</p:column>
    				
    			<p:column headerText="Role" sortBy="#{user.userRole}" filterPosition="bottom" filterBy="#{user.userRole}">
    				<h:outputText value="#{user.userRole}"/>
    			</p:column>	
    				
    			<p:column headerText="Actions">
        			<p:commandButton value="Edit" style="margin:5px"
        				actionListener="#{usersBean.editButtonClick(user)}"
        				oncomplete="editUserDialog.show()" update=":edit_form"
        				icon="ui-icon-arrowrefresh-1-w">
        				<f:setPropertyActionListener target="#{usersBean.user}" value="#{user}" />
        			 </p:commandButton>

					<p:commandButton value="Delete" style="margin:5px"
                    	update=":user_form:usersTable"
                        actionListener="#{usersBean.deleteButtonClick(user)}"
                        icon="ui-icon-circle-minus" >
                        <f:setPropertyActionListener target="#{usersBean.user}" value="#{user}" />      
                    </p:commandButton>
					<ui:include src="../protected/dialogs/confirm_user_removal.xhtml"/>
    			</p:column>	
			</p:dataTable>
		</h:form>
		</div>
		
		<ui:include src="../protected/dialogs/edit_user.xhtml"/>		
	</ui:define>
</ui:composition>    